﻿using System;
using System.Collections.Generic;
using System.Text;
using SharpDiary.Core.Data;
using SharpDiary.Core.Utility;

namespace SharpDiary.Core.ORMapping
{
    /// <summary>
    /// 提醒信息。
    /// </summary>
    [TableInfoAttribute("ReminderInfo")]
    public class ReminderInfo : DbMappingObjectBase
    {
        #region Fields & Properties

        private Int64 _id = -1;

        [FieldMapping(true, System.Data.DbType.Int64, true, true)]
        public Int64 Id
        {
            get { return _id; }
            set { _id = value; }
        }

        private Int64 _ownerTaskId = -1;

        [FieldMapping(false, System.Data.DbType.Int64, false, false)]
        public Int64 OwnerTaskId
        {
            get { return _ownerTaskId; }
            set { _ownerTaskId = value; }
        }

        private Int64 _reminderType = 0;

        /// <summary>
        /// 提醒类型。
        /// </summary>
        [FieldMapping(false, System.Data.DbType.Int64, false, false)]
        public Int64 ReminderType
        {
            get { return _reminderType; }
            set { _reminderType = value; }
        }

        private string _name = string.Empty;

        [FieldMapping(false, System.Data.DbType.String, false, false)]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private string _detail = string.Empty;

        [FieldMapping(false, System.Data.DbType.String, false, false)]
        public string Detail
        {
            get { return _detail; }
            set { _detail = value; }
        }

        private DateTime _alarmDatetime = DateTime.Now;

        [FieldMapping(false, System.Data.DbType.DateTime, false, false)]
        public DateTime AlarmDatetime
        {
            get { return _alarmDatetime; }
            set { _alarmDatetime = value; }
        }

        private Int64 _status = 1;

        [FieldMapping(false, System.Data.DbType.Int64, false, false)]
        public Int64 Status
        {
            get { return _status; }
            set { _status = value; }
        }

        /*
        private Int64 _reminderStyle = 1;

        [FieldMapping(false, System.Data.DbType.Int64, false, false)]
        public Int64 ReminderStyle
        {
            get { return _reminderStyle; }
            set { _reminderStyle = value; }
        }
        */

        #endregion

        #region Constructors

        public ReminderInfo() { }

        #endregion

        #region Methods

        /// <summary>
        /// 获取提醒总数。
        /// </summary>
        /// <returns></returns>
        public static int GetTotalCount()
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendLine("select count(*) as FCount from ReminderInfo");

            DataAccessService das = Utils.GetDataAccessServiceInstance();
            object result = das.ExecuteScalar(sql.ToString());

            return (result != null && result != DBNull.Value ? Convert.ToInt32(result) : 0);
        }

        /// <summary>
        /// 获取所有提醒信息。
        /// </summary>
        /// <returns></returns>
        public static List<ReminderInfo> GetAllDiaries()
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendLine("SELECT * FROM ReminderInfo");

            DataAccessService das = Utils.GetDataAccessServiceInstance();
            return DbObjectMappingHelper.QueryObjectList<ReminderInfo>(sql.ToString());
        }

        public override string ToString()
        {
            return (!string.IsNullOrEmpty(_name) ? UserSettings.ShellInstance.CryptionService.Decrypt(_name) : string.Empty);
        }



        #endregion
    }
}
